package com.damai.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import com.citywithincity.utils.IoUtil;

public class FileUtil {

	public static void scan(File dir,FileVisitor visitor){
		if(dir==null){
			return;
		}
		File[] files = dir.listFiles();
		if(files!=null){
			for (File file : files) {
				visitor.visitFile(file);
				if(file.isDirectory()){
					scan(file, visitor);
				}
			}
		}
		
		
	}
	
	/**
	 * 将文件从src拷贝到dest，注意，都是文件，不是目录
	 * @param src
	 * @param dest
	 * @throws IOException 
	 */
	public static void copy(File src,File dest) throws IOException{
		FileInputStream is = null;
		FileOutputStream os = null;
		try{
			is = new FileInputStream(src);
			os = new FileOutputStream(dest);
			IoUtil.copyAndCloseAll(is, os);
		}finally{
			IoUtil.close(is);
			IoUtil.close(os);
		}
		
		
	}
}
